package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemMakeOverPublishMainPatentBinding;
import com.sgb.kjwl.interfaces.PublishRecyclerClick;
import com.sgb.kjwl.model.entity.enterprise.PatentPublishEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PatentPublishAdapter  extends BaseRecycleAdapter<PatentPublishEntity> {

    PublishRecyclerClick<PatentPublishEntity> mPublishEntityPublishRecyclerClick;
    ItemMakeOverPublishMainPatentBinding mainPatentBinding;

    public void setmPublishEntityPublishRecyclerClick(PublishRecyclerClick<PatentPublishEntity> mPublishEntityPublishRecyclerClick) {
        this.mPublishEntityPublishRecyclerClick = mPublishEntityPublishRecyclerClick;
    }

    public PatentPublishAdapter(Context context, List<PatentPublishEntity> datas) {
        super(context, R.layout.item_make_over_publish_main_patent, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PatentPublishEntity talentEntity) {
        holder.setBinding(BR.entity, talentEntity);
        mainPatentBinding = (ItemMakeOverPublishMainPatentBinding) holder.getmBinding();

        holder.getItem().findViewById(R.id.tv_item_make_over_publish_main_up_and_down).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPublishEntityPublishRecyclerClick.recyclerClick(talentEntity);
            }
        });
        if (talentEntity.getImg() != null && !talentEntity.getImg().equals("")) {
            Glide.with(context).load(talentEntity.getImg()).apply(new RequestOptions()
                    .placeholder(R.mipmap.morentu_change)
                    .fallback( R.mipmap.morentu_change)
                    .error(R.mipmap.morentu_change)).into(mainPatentBinding.ivItemMakeOverPublishMainPicture);
        } else {
            switch (talentEntity.getCategoryName()){
                case "发明专利":
                    Glide.with(context).load(R.mipmap.qiyefuwu_module_famingzhuanli_for_patent_publish).into(mainPatentBinding.ivItemMakeOverPublishMainPicture);
                    break;
                case "实用新型":
                    Glide.with(context).load(R.mipmap.shiyongxinxing_patent_publish).into(mainPatentBinding.ivItemMakeOverPublishMainPicture);
                    break;
                case "外观设计":
                    Glide.with(context).load(R.mipmap.waiguansheji_patent_publish).into(mainPatentBinding.ivItemMakeOverPublishMainPicture);
                    break;
            }
        }
        if (null==talentEntity.getOrderStatus()||"3".equals(talentEntity.getOrderStatus())){
            mainPatentBinding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.VISIBLE);
            mainPatentBinding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_zai_shou_zhong));
        }else if("1".equals(talentEntity.getOrderStatus())||"2".equals(talentEntity.getOrderStatus())||"4".equals(talentEntity.getOrderStatus())){
            mainPatentBinding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.GONE);
            mainPatentBinding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_jiaoyizhong));
        }else if ("5".equals(talentEntity.getOrderStatus())){
            mainPatentBinding.tvItemMakeOverPublishMainUpAndDown.setVisibility(View.GONE);
            mainPatentBinding.imgSbStatus.setImageDrawable(context.getResources().getDrawable(R.mipmap.icon_yichushou));
        }
    }
}
